import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig((props) => {
  return {
    // 插件
    plugins: [react()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        '@components': path.resolve(__dirname, 'src/components'),
        '@utils': path.resolve(__dirname, 'src/utils'),
      },
    },
    server: {
      // 0.0.0.0 || true 表示监听所有地址
      host: true,
      // 端口号
      port: 3230,
      // 是否自动打开浏览器
      open: true,
      //跨域
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:3333',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
        '/xxapi': {
          target: 'https://v2.xxapi.cn',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(/^\/xxapi/, ''),
        },
      },
    },
    build: {
      //项目打包后的文件夹
      outDir: 'dist',
      // assetsDir:'public',  // 静态文件位置
      rollupOptions: {},
      minify: 'terser', // 使用 Terser 压缩
      terserOptions: {
        compress: {
          drop_console: true, // 去除 console.*
        },
      },
    },
    base: './',
  };
});
